//
//  QSWorkStateWithButtonCell.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/5/20.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSWorkStateWithButtonCell.h"
#import "QSWorkStationRemarkViewController.h"
#import "QSWorkStationInterface.h"
#import "TYAlertController.h"
@implementation QSWorkStateWithButtonCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    // Initialization code
}

- (void)layoutSubviews{
    [self configSubView];
}
- (void)configSubView{
    self.backgroundColor = [UIColor clearColor];
//    self.centerImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleFinish:)];
    [self.centerImageView addGestureRecognizer:tap];
}

- (void)handleFinish:(UITapGestureRecognizer *)tap{
    [QSAppKeyWindow showIndeterminateHudWithText:@""];
    [QSWorkStationInterface postFinishWorkWithId:self.model.ewId andBlock:^(ResponseMessage *rspStatusAndMessage, NSString *finishStr) {
        [QSAppKeyWindow hideHud];
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            QSWorkStationRemarkViewController *vc = [QSWorkStationRemarkViewController new];
            vc.workId = self.model.ewId;
            [[UIViewController currentViewController].navigationController pushViewController:vc animated:YES];
        }
    }];
    
    
}

- (void)setModel:(QSWorkDetailsModel *)model{
    _model = model;
    if (model.ewPersonState.intValue == 0) {
        [self.centerImageView setImage:[UIImage imageNamed:@"ic_work_unfinish"]];
        self.centerLabel.hidden = NO;
        self.tipsLabel.text = @"若有疑问，可联系发起人";
        self.centerImageView.userInteractionEnabled = YES;
        self.contactButton.userInteractionEnabled = YES;
        [self.contactButton setTitle:@"联系发起人" forState:UIControlStateNormal];
        [self.contactButton setTitleColor:[UIColor colorWithHexString:@"#777CB3"] forState:UIControlStateNormal];

    }else{
        [self.centerImageView setImage:[UIImage imageNamed:@"ic_work_finish"]];
        self.centerLabel.hidden = YES;
        self.tipsLabel.text = @"恭喜您已完成！";
        self.centerImageView.userInteractionEnabled = NO;
        self.contactButton.userInteractionEnabled = NO;
        [self.contactButton setTitle:[NSString stringWithFormat:@"完成时间：%@", [NSDate dateWithTimestamp:model.ewFinishTime format:@"yyyy-MM-dd HH:mm"]] forState:UIControlStateNormal];
        [self.contactButton setTitleColor:[UIColor QSColorBlack666666] forState:UIControlStateNormal];
    }
}
- (IBAction)cotactAction:(UIButton *)sender {
    
    [TYAlertController showAlertViewWithTitle:@"联系发起人" message:_model.ewCreateUserName confirmTitle:@"确认呼叫" cancelTitle:@"取消" confirmAction:^{
        NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@", self.model.ewCreateUserPhone];
        
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    } cancelAction:^{
        
    }];
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
